package com.universe.titan.module.socketTest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.universe.titan.server.MessageHandle;
import com.universe.titan.server.MessageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Author : linmaobo
 * @create 2022/12/13
 */
@RestController
@RequestMapping("/socket-test")
public class SocketTestController {

    @Autowired
    MessageHandle messageHandle;

    /**
     * 发送单人
     * @param message
     * @throws IOException
     */
    @PostMapping("/single")
    public  void  single(@RequestBody MessageInfo message) throws IOException {
        messageHandle.sendToOneUser(message);
    }

    /**
     * 发送所有人
     * @param message
     * @throws IOException
     */
    @PostMapping("/multi")
    public  void  multi(@RequestBody MessageInfo message) throws IOException {
        messageHandle.broadcast(message);
    }
}
